package com.hands.voice.service.impl;

import com.hands.commen.entity.commen.HandleResult;
import com.hands.commen.entity.commen.SearchInfo;
import com.hands.commen.entity.wx.MsgEntity;
import com.hands.commen.entity.wx.MsgHeader;
import com.hands.commen.utils.RandomUtils;
import com.hands.service.VoiceRpcService;
import com.hands.voice.mapper.HandleResultMapper;
import com.hands.voice.mapper.SearchInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
//@Service
public class VoiceServiceImpl implements VoiceRpcService {

    @Autowired
    private SearchInfoMapper searchInfoMapper;

    @Autowired
    private HandleResultMapper handleResultMapper;

    @Override
    public String InstructionsVoiceInfo(String msg){

        List<SearchInfo> searchInfo = searchInfoMapper.selectSearchInfoBySearchKey(msg);

        System.out.println("查询相应的Key"+searchInfo);

        List<Integer> topicPaths = searchInfo.stream().map(SearchInfo::getId).collect(Collectors.toList());
        List<String> collect = topicPaths.stream().map(String::valueOf).collect(Collectors.toList());
        String join = String.join(",", collect);
        //根据相应的key查询对话答案以及处理

        List<HandleResult> handleResults = handleResultMapper.selectHandleResultBySearchKey(join);
        HandleResult handleResult=null;
        if(handleResults.size()>0){
             handleResult = handleResults.get(0);
        }


        //        if(handleResults.size()>0){
//
//        }


        //判断是跳转下一个还是语音播放


        return join;
    }
}
